const app = getApp()
const util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    canCommit1: false,
    canCommit2: false,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    util.share();
    let self = this;
    wx.getStorage({
      key: 'key',
      success: (res) => {
        self.setData({
          member_key: res.data
        });
        self.checkPwdTime();
      }
    })
  },
  /**
   * step4 验证第四步  是否超时
   */
  checkPwdTime: function () {
    var self = this;
    /*wx.showLoading({
      title: "加载中",
    })*/

    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=member_account&op=modify_password_step4',
      method: "POST",
      data: {
        key: self.data.member_key,
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        if (res.data.code == 200) {
          
        } else {
          wx.navigateBack({
            delta: 1
          });
          wx.showToast({
            title: res.data.datas.error,
            icon: 'none'
          })
        }
      },
      fail: function (res) {
        /*wx.showToast({
          title: '网络请求失败',
          icon: 'none'
        })*/
      }
    })
  },
  /*
   *监听充值卡的输入
   */
  cardInput1: function(event) {
    var self = this;
    self.setData({
      canCommit1: this.inputLisener(event),
    });
  },
  cardInput2: function(event) {
    var self = this;
    self.setData({
      canCommit2: this.inputLisener(event),
    });
  },
  /**
   * input 监听
   */
  inputLisener: function(event) {
    var self = this;
    if (event.detail.value.length > 0) {
      return true;
    } else {
      return false;
    }
  },
  /**
   * 提交
   */
  commitPws: function(event) {
    var self = this;
    let detail = event.detail.value;
    if (detail.pwd1!=detail.pwd2){
      wx.showToast({
        title: '两次密码输入不一致',
        icon: 'none'
      });
      return;
    }
    wx.showLoading({
      title: "加载中",
    })
    
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=member_account&op=modify_password_step5',
      method: "POST",
      data: {
        key: self.data.member_key,
        password: detail.pwd1,
        password1: detail.pwd2,
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function(res) {
        if (res.data.code == 200) {
          wx.navigateBack({
            delta: 2
          });
          wx.showToast({
            title: '密码修改成功',
            icon: 'none'
          });
        } else {
          wx.showToast({
            title: res.data.datas.error,
            icon: 'none'
          })
        }
      },
      fail: function(res) {
        wx.showToast({
          title: '网络请求失败',
          icon: 'none'
        })
      }
    })
  }
})